﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Pivot;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using PivotViewerBase.Web;

namespace PivotViewerBase
{
    public partial class MainPage : UserControl
    {

        public List<string> lstLegend;

        private AdventureWorksDomainContext ctx = new AdventureWorksDomainContext();

        public MainPage()
        {
            InitializeComponent();

            var x = ctx.GetVStoreWithDemographicsQuery();
 
            //pViewer.ItemsSource = DinnerParty.BuildData();
            //pViewer.ItemsSource = PivotViewerBase.Web.vStoreWithDemographic;

            lstLegend = new List<string>() { "Mountain", "Road", "Touring" };



        }


        private void pViewer_ViewChanged_1(object sender, EventArgs e)
        {

        }

        private void basicAdorner_CommandsRequested(object sender,
    PivotViewerCommandsRequestedEventArgs e)
        {
            if (e.IsItemSelected)
            {
                e.Commands.Add(new AddCommand());
                e.Commands.Add(new MyCommand());
            }
        }

        private void vStoreWithDemographicDomainDataSource_LoadedData_2(object sender, LoadedDataEventArgs e)
        {
           // pViewer.ItemsSource = vStoreWithDemographicDomainDataSource.DataView;
           /// pViewer.View = pViewer.GraphView;
            if (e.HasError)
            {
                System.Windows.MessageBox.Show(e.Error.InnerException.ToString() + "<br><br>Hello", "Load Error", System.Windows.MessageBoxButton.OK);
                e.MarkErrorAsHandled();
            }
        }
    }

    public class Legend
    {
        // The default constructor is required for creation from XAML.
        public Legend()
        {
        }

        // The LegendName property is a string that holds the first and last name.
        public string LegendName { get; set; }

        // The IsEnrolled property gets or sets a value indicating whether
        // the Legend is currently enrolled.
        // public bool IsEnrolled { get; set; }
    }

    // The LegendList collection is declared for convenience,
    // because declaring generic types in XAML is inconvenient.
    public class LegendList : ObservableCollection<Legend>
    {

    }


    public class AddCommand : IPivotViewerUICommand
    {

        public string DisplayName
        {
            get { return "Add Item"; }
        }

        public Uri Icon
        {
            get { return null; }
        }

        public object ToolTip
        {
            get { return "Add Item to cart."; }
        }

        public bool CanExecute(object parameter)
        {
            return true;
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            var itm = parameter as PivotViewerBase.Web.vStoreWithDemographic;
            MessageBox.Show(itm.Name + " was selected");
        }
    }


    public class MyCommand : IPivotViewerUICommand
    {

        public string DisplayName
        {
            get { return "Mine"; }
        }

        public Uri Icon
        {
            get { return null; }
        }

        public object ToolTip
        {
            get { return "All mine."; }
        }

        public bool CanExecute(object parameter)
        {
            return true;
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            var itm = parameter as PivotViewerBase.Web.vStoreWithDemographic;
            MessageBox.Show(itm.Name + " was selected");

            /* Here we call a stored proc on the db server and pass its 
             * results on to a child window
             */

            /// itm.BusinessEntityID
            /// 


        }
    }



}
